package mediatheque.view;

import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import mediatheque.model.DocumentModel;
import mediatheque.model.LivreModel;
import mediatheque.model.MediathequeModel;

public class LivreView extends DocumentView {
	
	private static final long serialVersionUID = -5408017362714236082L;

    protected JLabel lblAuteur;
    protected JLabel lblEditeur;
    protected JLabel lblISBN;   
    
    protected JTextField tfAuteur;
    protected JTextField tfEditeur;
    protected JTextField tfISBN; 
	
	public LivreView(MediathequeModel model) {
		super(model, "Gestion de document : Livre", null);
		
		setSize(410, 480);
	}
	
	@Override
	protected void initialiserComposants() {
        lblAuteur = new JLabel("Auteur : ");
        tfAuteur = new JTextField();
        lblEditeur = new JLabel("Editeur : ");
        tfEditeur = new JTextField();
        lblISBN = new JLabel("ISBN : ");
        tfISBN = new JTextField();
        
		super.initialiserComposants();        
	}
	
	protected void placerComposants() {
		GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(203, 203, 203)
                .addComponent(btnEnregistrer, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAnnuler, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lblAuteur, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblEditeur, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
                            .addComponent(lblISBN, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(tfISBN, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(tfEditeur, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(tfAuteur, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(lblNom, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(lblEtat, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(lblDescription, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(tfNom, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(cbEtat, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE))
                        .addGap(13, 13, 13))
                    .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblTitre, GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(lblTitre, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(tfNom, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblNom, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 157, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(cbEtat, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblEtat, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 9, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(tfAuteur, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblAuteur, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(tfEditeur, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblEditeur, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(tfISBN, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblISBN, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(btnAnnuler)
                        .addComponent(btnEnregistrer))
                    .addContainerGap())
            );

	}

	
	public String getValeurAuteur(){
		return tfAuteur.getText();
	}
	
	public String getValeurEditeur(){
		return tfEditeur.getText();
	}
	
	public String getValeurISBN(){
		return tfISBN.getText();
	}
	
	
	public void setValeurAuteur(String v){
		tfAuteur.setText(v);
	}
	
	public void setValeurEditeur(String v){
		tfEditeur.setText(v);
	}
	
	public void setValeurISBN(String v){
		tfISBN.setText(v);
	}
		
	@Override
	public void setValeurs(DocumentModel document) {
		setValeurAuteur(((LivreModel) document).getAuteur());
		setValeurEditeur(((LivreModel) document).getEditeur());
		setValeurISBN(((LivreModel) document).getISBN());
		super.setValeurs(document);
	}

}
